﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Management;
using DevExpress.Web.ASPxEditors;
// using AUSRIS.Data.Web.ReportServiceProd;
using System.Web.Security;


namespace AUSRIS.Data.Web.Admin
{
	public partial class AdminSSRS : System.Web.UI.Page
	{

		// private ReportingService2005 rs;
		// private ReportExecutionService re;



		protected void Page_Load(object sender,EventArgs e)
		{
			//if(!IsPostBack)
			//{
			//    this.lblError.Visible = false;
			//}
			//// GetReportServerWMI("maxap04602");
			//InitReportingService();
		}

		//private void GetReportServerWMI(string machineName)
		//{

		//    string reportServerUrl = String.Empty;
		//    string wmiNamespace = @"\\" + machineName + @"\root\Microsoft\SqlServer\ReportServer\v9";
		//    ManagementScope managementScope = null;
		//    ConnectionOptions connectionOptions = new ConnectionOptions();
		//    connectionOptions.Authentication = AuthenticationLevel.PacketPrivacy;

		//    try
		//    {
		//        managementScope = new ManagementScope(wmiNamespace,connectionOptions);
		//        managementScope.Connect();
		//        ManagementPath managementPath = new ManagementPath("MSReportServer_Instance");
		//        ManagementClass managementClass = new ManagementClass(managementScope,managementPath,new ObjectGetOptions());
		//        managementClass.Get();

		//        if(managementClass == null)
		//        {
		//            throw new Exception("No WMI class found.");
		//        }

		//        foreach(ManagementObject managementObject in managementClass.GetInstances())
		//        {
		//            managementObject.Get();
		//            reportServerUrl = (string)managementObject["ReportServerUrl"];
		//            reportServerUrl = reportServerUrl + @"/ReportService2005.asmx";
		//            foreach(PropertyData prop in managementObject.Properties)
		//            {
		//                this.lbSSRS.Items.Add(new ListEditItem(prop.Name,prop));
		//            }
		//        }
		//    }
		//    catch(Exception ex)
		//    {
		//        // throw new Exception("An error occurred while attempting to get the ReportServer Url.", ex);
		//        this.lblError.Text="An error occurred while attempting to get the ReportServer Url.";
		//        this.lblError.Visible = true;
		//        this.memoErrorMessage.Text = ex.Message + "\n";
		//        //this.memoErrorMessage.Text = this.memoErrorMessage.Text + ex.InnerException.ToString();
		//    }


		//}


		//private void InitExecutionService()
		//{

		//}


		//private void InitReportingService()
		//{
		//    //FormsAuthenticationTicket authenticationTicket = new FormsAuthenticationTicket("superuser",true,30);
		//    //FormsIdentity formsId = new FormsIdentity(authenticationTicket);
		

		//    rs = new ReportingService2005();
		//    // rs.Url = "https://ausris-integration.maxwell.af.mil/Reports/ReportService2005.asmx";
		//    // rs.Url = "https://ausris.maxwell.af.mil/Reports/ReportService2005.asmx";
		//    // rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
		//    // rs.Credentials = new System.Net.NetworkCredential("superuser","P@$$w0rd");
		//    // rs.Credentials
		//    CatalogItem[] items = rs.ListChildren("/",true);

		//    Console.WriteLine(String.Format("{0}",items.Length.ToString()));
			

		//    //List<CatalogItem> catalogItems = new List<CatalogItem>();
		//    //foreach(CatalogItem item in rs.ListChildren("/",true))
		//    //{
		//    //    catalogItems.Add(item);
		//    //}

		//    //this.lbSSRS.DataSource = catalogItems;
		//    //this.lbSSRS.DataBind();
			 
			
		//}
	}
}